package server;

import java.util.AbstractMap;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class ConnectionMap extends AbstractMap<Integer, Connection>
{
	private final HashMap<Integer, Connection> allConnections;
	private final HashMap<Integer, Connection> serverConnections;
	
	public ConnectionMap()
	{
		this.allConnections = new HashMap<Integer, Connection>();
		this.serverConnections = new HashMap<Integer, Connection>();
	}
	
	@Override
	public Set<java.util.Map.Entry<Integer, Connection>> entrySet()
	{
		return allConnections.entrySet();
	}
	@Override
	public Connection put(Integer key, Connection value)
	{
		return allConnections.put(key, value);
	}
	@Override
	public Connection remove(Object key)
	{
		serverConnections.remove(key);
		
		return allConnections.remove(key);
	}
	@Override
	public void clear()
	{
		allConnections.clear();
		serverConnections.clear();
	}
	@Override
	public boolean containsKey(Object key)
	{
		return allConnections.containsKey(key);
	}
	@Override
	public boolean containsValue(Object value)
	{
		return allConnections.containsValue(value);
	}
	@Override
	public Connection get(Object key)
	{
		return allConnections.get(key);
	}
	@Override
	public Set<Integer> keySet()
	{
		return allConnections.keySet();
	}
	@Override
	public int size()
	{
		return allConnections.size();
	}
	@Override
	public void putAll(Map<? extends Integer, ? extends Connection> m)
	{
		allConnections.putAll(m);
	}
	@Override
	public Collection<Connection> values()
	{
		return allConnections.values();
	}
	@Override
	public boolean isEmpty()
	{
		return allConnections.isEmpty();
	}
	public void putServerConnection(int key, Connection value)
	{
		allConnections.put(key, value);
		serverConnections.put(key, value);
	}
	public Collection<Connection> serverConnectionValues()
	{
		return serverConnections.values();
	}
}
